package com.example.supermarket.mapper;

import com.example.supermarket.pojo.Customer;
import com.example.supermarket.pojo.Item;
import com.example.supermarket.pojo.LineItem;
import com.example.supermarket.pojo.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CustomerMapper {

    @Select("select * from customer where user_id=#{userId}")
    Customer findByUserId(Integer userId);

    @Insert("insert into `order`(customer_id,shop_id,status,deleted,total)" +
            "values (#{customerId},#{shopId},0,0,#{total})")
    void createOrder(Order order);

    @Insert("insert into lineItem(order_id,item_id,quantity) values (#{orderId},#{itemId},#{quantity})")
    void createLineItem(LineItem lineItem);

    @Update("update `order` set total=#{total} where order_id=#{orderId}")
    void updateOrderTotal(Integer total,Integer orderId);

    @Update("update `order` set status=#{status} where order_id=#{orderId}")
    void updateOrderStatus(Integer status,Integer orderId);

    @Update("update `order` set deleted=1 where order_id=#{orderId}")
    void deleteOrder(Integer orderId);

    @Select("select order_id from `order` where customer_id=#{customerId} and shop_id=#{shopId} and status=0 and deleted!=1")
    Integer findOrderId(Order order);

    @Select("select * from `order` where customer_id=#{customerId} and shop_id=#{shopId} and status=0 and deleted!=1")
    Order findCustomerOrder(Integer customerId,Integer shopId);
    @Select("select * from lineitem where order_id=#{orderId}")
    List<LineItem> findItemByOrderId(Integer orderId);

    @Select("select * from `order` where order_id=#{orderId}")
    Order findOrderByOrderId(Integer orderId);

    @Select("select * from `order` where customer_id=#{customerId}")
    List<Order> findHistoryOrder(Integer customerId);

    @Select("select * from customer where customer_id=#{customerId}")
    Customer getCustomerByCustomerId(Integer customerId);
}
